clear
clc
close all

load RTDB_TAB3
A=US_CPI;nn=size(A,2);

for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,1)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=US_ULC;
for j=2:27
    Y4(j-1)=A(j+1,(j-1)*2+j+3);Y6(j-1)=A(j+1,(j-1)*2+j+5);Y8(j-1)=A(j+1,(j-1)*2+j+7);
    Y12(j-1)=A(j+1,(j-1)*2+j+11);Y16(j-1)=A(j+1,(j-1)*2+j+15);Y24(j-1)=A(j+1,(j-1)*2+j+23);
end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,2)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=US_GDP;
for j=2:27
    Y4(j-1)=A(j+1,(j-1)*2+j+3);Y6(j-1)=A(j+1,(j-1)*2+j+5);Y8(j-1)=A(j+1,(j-1)*2+j+7);
    Y12(j-1)=A(j+1,(j-1)*2+j+11);Y16(j-1)=A(j+1,(j-1)*2+j+15);Y24(j-1)=A(j+1,(j-1)*2+j+23);
end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,3)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=US_IP;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,4)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=US_UR;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,5)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=US_M3;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr(:,6)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TAB_agr=round(TAB_agr*100)/100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_CPI;nn=size(A,2);

for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr_jp(:,1)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_ULC;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(1:77,87));%discontinued
Stdtot=nanstd(A(1:77,87));%discontinued
TAB_agr_jp(:,2)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_GDP;
for j=2:27
    Y4(j-1)=A(j+1,(j-1)*2+j+3);Y6(j-1)=A(j+1,(j-1)*2+j+5);Y8(j-1)=A(j+1,(j-1)*2+j+7);
    Y12(j-1)=A(j+1,(j-1)*2+j+11);Y16(j-1)=A(j+1,(j-1)*2+j+15);Y24(j-1)=A(j+1,(j-1)*2+j+23);
end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr_jp(:,3)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_IP;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr_jp(:,4)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_UR;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr_jp(:,5)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=JP_M3;
for j=2:nn-23,Y4(j-1)=A(j+1,j+3);end;for j=2:nn-23,Y6(j-1)=A(j+1,j+5);end
for j=2:nn-23,Y8(j-1)=A(j+1,j+7);end;for j=2:nn-23,Y12(j-1)=A(j+1,j+11);end
for j=2:nn-23,Y16(j-1)=A(j+1,j+15);end;for j=2:nn-23,Y24(j-1)=A(j+1,j+23);end

MeCum=[nanmean(-Y24+Y4) nanmean(-Y24+Y6) nanmean(-Y24+Y8)...
    nanmean(-Y24+Y12) nanmean(-Y24+Y16) ];
StdCum=[nanstd(-Y24+Y4) nanstd(-Y24+Y6) nanstd(-Y24+Y8)...
    nanstd(-Y24+Y12) nanstd(-Y24+Y16)  ];
Metot=nanmean(A(:,end));
Stdtot=nanstd(A(:,end));
TAB_agr_jp(:,6)=[Metot; MeCum';Stdtot; StdCum'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TAB_agr_jp=round(TAB_agr_jp*100)/100;

disp(' ')
disp('--------------------------------------------------------------------------------------------------------------------')

disp('                           CPI      ULC     RGDP      IP       UR      M3 ')
disp('                                       United States                 ')

disp(['Mean','                       ', num2str(TAB_agr(1,:),2)])
disp('Mean of revisions')
disp(['Y_{t|t+4}-Y_{t|t+24}','         ', num2str(TAB_agr(2,:),2)])
disp(['Y_{t|t+6}-Y_{t|t+24}','         ', num2str(TAB_agr(3,:),2)])
disp(['Y_{t|t+8}-Y_{t|t+24}','         ', num2str(TAB_agr(4,:),2)])
disp(['Y_{t|t+12}-Y_{t|t+24}','        ', num2str(TAB_agr(5,:),2)])
disp(['Y_{t|t+16}-Y_{t|t+24}','        ', num2str(TAB_agr(6,:),2)])
disp(['Standard deviation','         ', num2str(TAB_agr(7,:),2)])
disp('Standard deviation of revisions')
disp(['Y_{t|t+4}-Y_{t|t+24}','         ', num2str(TAB_agr(8,:),2)])
disp(['Y_{t|t+6}-Y_{t|t+24}','         ', num2str(TAB_agr(9,:),2)])
disp(['Y_{t|t+8}-Y_{t|t+24}','         ', num2str(TAB_agr(10,:),2)])
disp(['Y_{t|t+12}-Y_{t|t+24}','        ', num2str(TAB_agr(11,:),2)])
disp(['Y_{t|t+16}-Y_{t|t+24}','        ', num2str(TAB_agr(12,:),2)])
disp('                                            Japan                 ')
disp(['Mean','                     ', num2str(TAB_agr_jp(1,:),2)])
disp('Mean of revisions')
disp(['Y_{t|t+4}-Y_{t|t+24}','      ', num2str(TAB_agr_jp(2,:),2)])
disp(['Y_{t|t+6}-Y_{t|t+24}','      ', num2str(TAB_agr_jp(3,:),2)])
disp(['Y_{t|t+8}-Y_{t|t+24}','      ', num2str(TAB_agr_jp(4,:),2)])
disp(['Y_{t|t+12}-Y_{t|t+24}','    ', num2str(TAB_agr_jp(5,:),2)])
disp(['Y_{t|t+16}-Y_{t|t+24}','    ', num2str(TAB_agr_jp(6,:),2)])
disp(['Standard deviation','        ', num2str(TAB_agr_jp(7,:),2)])
disp('Standard deviation of revisions')
disp(['Y_{t|t+4}-Y_{t|t+24}','      ', num2str(TAB_agr_jp(8,:),2)])
disp(['Y_{t|t+6}-Y_{t|t+24}','      ', num2str(TAB_agr_jp(9,:),2)])
disp(['Y_{t|t+8}-Y_{t|t+24}','       ', num2str(TAB_agr_jp(10,:),2)])
disp(['Y_{t|t+12}-Y_{t|t+24}','     ', num2str(TAB_agr_jp(11,:),2)])
disp(['Y_{t|t+16}-Y_{t|t+24}','     ', num2str(TAB_agr_jp(12,:),2)])